package cst.a328zf.widgettest328zf;

import android.content.Intent;
import android.net.sip.SipAudioCall;
import android.support.annotation.IdRes;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private EditText inputtext;
    private ImageView imageview;
    private Button txtbutton,changebutton,sexbutton,interbutton;
    private RadioButton radiobutton,radiobutton2;
    private CheckBox checkBox,checkBox2,checkBox3;
    private ImageButton imagebutton;
    private RadioGroup rg;
    private LinearLayout ll;
    private List<CheckBox> checkBoxs = new ArrayList<>();


    private void init(){
        inputtext=(EditText)findViewById(R.id.inputtext);
        txtbutton=(Button)findViewById(R.id.txtbutton);
        imageview=(ImageView)findViewById(R.id.imageView);
        changebutton=(Button)findViewById(R.id.changebutton);
        imagebutton=(ImageButton)findViewById(R.id.imageButton);
        sexbutton=(Button)findViewById(R.id.sexbutton);
        radiobutton=(RadioButton)findViewById(R.id.radioButton);
        radiobutton2=(RadioButton)findViewById(R.id.radioButton2);
        interbutton=(Button)findViewById(R.id.interbutton);
        checkBox=(CheckBox)findViewById(R.id.checkBox);
        checkBox2=(CheckBox)findViewById(R.id.checkBox2);
        checkBox3=(CheckBox)findViewById(R.id.checkBox3);
        rg=(RadioGroup)findViewById( R.id.RadioGroup);
        //ll=(LinearLayout) findViewById( R.id.LinearLayout);
        radiobutton2.setChecked(true);
        checkBox3.setChecked(true);

    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
        txtbutton.setOnClickListener(this);
        changebutton.setOnClickListener(this);
        imagebutton.setOnClickListener(this);
        sexbutton.setOnClickListener(this);
        interbutton.setOnClickListener(this);

        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            }
        });
        checkBoxs.add(checkBox);
        checkBoxs.add(checkBox2);
        checkBoxs.add(checkBox3);



        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                switch (checkedId){
                    case  R.id.radioButton:
                        inputtext.setText("女");
                        break;
                    case  R.id.radioButton2:
                        inputtext.setText("男");
                        break;
                }
            }
        });

    }



    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.txtbutton:
                Toast.makeText(this, "内容是"+inputtext.getText().toString(), Toast.LENGTH_SHORT).show();
                break;
            case R.id.changebutton:
                imageview.setImageResource(R.drawable.eclipse);
                imageview.setScaleType(ImageView.ScaleType.FIT_CENTER);
                break;
            case R.id.imageButton:
                Intent intent=new Intent(MainActivity.this,buttonActivity.class);
                intent.putExtra("para1",inputtext.getText().toString());
                startActivity(intent);
                break;
            case R.id.sexbutton:
                if(radiobutton.isChecked()) inputtext.setText("nv");
                if(radiobutton2.isChecked()) inputtext.setText("nan");
                break;
            case R.id.interbutton:
                String content="";
                for (CheckBox checkBox : checkBoxs) {

                    if (checkBox.isChecked()) {
                        content+=checkBox.getText()+"\n";
                    }
                }
                new AlertDialog.Builder(this).setMessage(content).setTitle("选中的内容如下")
                                .setPositiveButton("关闭", null).show();


        }


    }
}
